package com.lg.mvc.controller;

import com.lg.domain.User;
import com.lg.mvc.TT;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.LinkedBlockingQueue;

@Api(tags = "服务测试")
@RestController
@RequestMapping("/base")
public class BaseController {
    @Value("${server.port}")
    private String serverPort;

    /**
     * 美团高性能队列 对比
     */
    private LinkedBlockingQueue linkedBlockingQueue = new LinkedBlockingQueue<User>();

    @GetMapping("/baseConfig")
    public String getBaseConfig(){
        String key = TT.TT1.getKey();
        return serverPort;
    }

    @GetMapping("consumeLinkBlock")
    public void consumeLinkedBlockingQueue() {
        try {
            linkedBlockingQueue.take();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    @GetMapping("productLinkBlock")
    public void productLinkedBlockingQueue(Integer num) {
        try {
            for (int i = 0; i < num; i++) {
                User user = new User("gg"+i);
                linkedBlockingQueue.put(user);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }



}
